Elu

逐元素计算指数线性单元(Exponential Linear Unit,ELU)。

\[\begin{split}\mathrm{output}_i = \begin{cases} \mathrm{input}_i, & \mathrm{input}_i \ge 0 \\ \alpha \cdot (e^{\mathrm{input}_i} - 1), & \mathrm{input}_i < 0 \end{cases}\end{split}\]

其中 alpha 为标量,控制负半轴饱和程度。

输入:
  • input - 输入数据地址

  • alpha - ELU 系数(标量);fp16 接口为 float16

  • length - 元素个数

  • core_mask - 核掩码(仅共享存储版本)

输出:
  • output - 输出地址,长度与 input 相同

支持平台:

FT78NE MT7004

备注

  • FT78NE 支持 int8、fp32

  • MT7004 支持 fp16、fp32

共享存储版本:

void i8_elu_s(int8_t *input, int8_t *output, int8_t alpha, int length, int core_mask)
void hp_elu_s(float16 *input, float16 *output, float16 alpha, int length, int core_mask)
void fp_elu_s(float *input, float *output, float alpha, int length, int core_mask)

C调用示例:

 1// MT7004 示例(共享存储多核,DDR 地址)
 2void TestEluSMCFp32(int length, float alpha, int core_mask) {
 3    int core_id = get_core_id();
 4    int logic_core_id = GetLogicCoreId(core_mask, core_id);
 5    int core_num = GetCoreNum(core_mask);
 6    float *input = (float *)0x81000000;
 7    float *output = (float *)0x82000000;
 8    sys_bar(0, core_num);
 9    fp_elu_s(input, output, alpha, length, core_mask);
10}
11
12void main() {
13    int core_mask = 0b1111;
14    TestEluSMCFp32(1024, 0.9f, core_mask);
15}

私有存储版本:

void i8_elu_p(int8_t *input, int8_t *output, int8_t alpha, int length)
void hp_elu_p(float16 *input, float16 *output, float16 alpha, int length)
void fp_elu_p(float *input, float *output, float alpha, int length)

C调用示例:

 1// MT7004 示例(私有存储单核,AM 地址)
 2void TestEluAMFp32(int length, float alpha) {
 3    float *input = (float *)0x10010000;
 4    float *output = (float *)0x10020000;
 5    fp_elu_p(input, output, alpha, length);
 6}
 7
 8void main() {
 9    TestEluAMFp32(1024, 0.9f);
10}